//
//  NewsAndAdviceManager.m
//  YIChuSeller
//
//  Created by 田小椿 on 2018/12/26.
//  Copyright © 2018年 xiangshengjun. All rights reserved.
//

#import "NewsAndAdviceManager.h"
#import "GXNewsModel.h"
@implementation NewsAndAdviceManager

+ (void)addUserAdviceWithUserId:(NSString *)userId value:(NSString *)valueStr success:(CompleteHandle)success fail:(CompleteHandle)fail
{
    [SVProgressHUD showWithStatus:@"提交中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"YCS_INSERT_FEEDBACK",
                @"parameters":@{
                        @"userId":userId,
                        @"value":valueStr
                        }
                };
    [HttpHelper Post:@"ycs/Store/Store.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD showSuccessWithStatus:@"提交成功"];
            success(responseObject);
        }else{
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}

+ (void)selectShopSystemMessageWithStoreID:(NSString *)storeId success:(CompleteHandle)success fail:(CompleteHandle)fail
{
    [SVProgressHUD show];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"YCS_SELECT_STORE_MESSAGE",
                @"parameters":@{
                        @"storeId":storeId
                        }
                };
    [HttpHelper Post:@"ycs/Message/Message.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD dismiss];
                NSArray *contentArr = responseObject[@"result"][@"messages"];
                if (!contentArr.count) {
                    [SVProgressHUD showImage:nil status:@"无数据"];
                }
                NSMutableArray * dataArray = [NSMutableArray array];
                for (NSDictionary *dict in contentArr) {
                    GXNewsModel * model = [GXNewsModel mj_objectWithKeyValues:dict];
                    [dataArray addObject:model];
                }
                success(dataArray);
        }else{
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}

+ (void)selectShopOrderMessageWithStoreID:(NSString *)storeId success:(CompleteHandle)success fail:(CompleteHandle)fail
{
    [SVProgressHUD show];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"YCS_MESSAGE_FINDORDEMESSAGE",
                @"parameters":@{
                        @"storeId":storeId,
                        @"userId":@""
                        }
                };
    [HttpHelper Post:@"ycs/Message/Message.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD dismiss];
            NSArray *contentArr = responseObject[@"result"][@"messages"];
            if (!contentArr.count) {
                [SVProgressHUD showImage:nil status:@"无数据"];
            }
            NSMutableArray * dataArray = [NSMutableArray array];
            for (NSDictionary *dict in contentArr) {
                GXNewsModel * model = [GXNewsModel mj_objectWithKeyValues:dict];
                [dataArray addObject:model];
            }
            success(dataArray);
        }else{
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}

+ (void)changeShopOrderStateWithStoreID:(NSString *)storeId state:(NSString *)stateStr success:(CompleteHandle)success fail:(CompleteHandle)fail
{
    [SVProgressHUD showWithStatus:@"提交中" maskType:SVProgressHUDMaskTypeClear];
    NSDictionary * jsonStr = [NSDictionary dictionary];
    jsonStr = @{@"api":@"YCS_UPDATE_STORE_STATE",
                @"parameters":@{
                        @"storeId":storeId,
                        @"state":stateStr
                        }
                };
    [HttpHelper Post:@"ycs/Store/Store.do" parameters:jsonStr success:^(id responseObject) {
        if ([responseObject[@"cod"] isEqualToString:@"001"]) {
            [SVProgressHUD showSuccessWithStatus:@"提交成功"];
            success(responseObject);
        }else{
            [SVProgressHUD showErrorWithStatus:responseObject[@"describa"]];
        }
    } failure:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:@"请求数据失败"];
    }];
}


@end
